import { createRouter, createWebHistory } from 'vue-router'
import { global } from '@/utils/status';
/*
  meta: 
    show: 是否显示在侧边栏
    isLink: name是否可在侧边栏用于跳转路由
    icon: 侧边栏路由显示的icon类名
    title: 显示的页面标题和侧边栏标题
    rewriteTitle: 是否需要将userStore的modalName添加进title中，进行title重构
    role: 用户角色
    children-index: 子路由是否作为侧边栏的链接项(子路由的index为所有子路由中唯一的true)
    exclude: 是否不做keepAlive缓存
*/

// 公共路由-无权限
export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    meta: { title: '登录', show: false, isLink: false },
    component: () => import('@/views/login/login.vue'), 
    // component: () => import('@/views/login/login1.vue'), 
    // component: () => import('@/page/login2.vue')
    // component: () => import('@/page/login3.vue')
    // component: () => import('@/page/login4.vue')
  },
  {
    path: '/test',
    name: 'test',
    meta: { title: '测试', show: false, isLink: false },
    component: () => import('../views/Test.vue')
  }
];
// 动态路由-权限筛选
export const dynamicRoutes = [
  {
    path: '',
    component: () => import('@/components/layout'),
    redirect: '/moduleLibManager',
    name: 'moduleLib',
    meta: { show: true, icon: 'icon-home', isLink: false, title: '隐写模块库管理', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER ] },
    children: [
      // 模块库管理
      {
        path: '/moduleLibManager',
        name: 'moduleLibManager',
        meta: { show: true, icon: 'icon-guanli1', isLink: true, title: '模块库管理', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER ] },
        component: () => import('@/views/moduleLib/moduleLibManager.vue')
      },
      // 创建模块库
      {
        path: '/moduleLibCreate',
        name: 'moduleLibCreate',
        meta: { show: true, icon: 'icon-wochuangjiande', isLink: true, title: '模块库创建', rewriteTitle: true, exclude: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER ] },
        component: () => import('@/views/moduleLib/moduleLibCreate.vue')
      }
    ]
  },
  // 算法模块部分
  {
    path: '',
    component: () => import('@/components/layout'),
    redirect: '/index',
    name: 'module',
    meta: { show: true, icon: 'icon-ai-module', isLink: false, title: '隐写模块管理', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER ] },
    children: [
      // 模块算法管理
      { 
        path: '/index',
        name: 'moduleManage',
        meta: { show: true, icon: 'icon-guanli2', isLink: true, title: '算法模块管理', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER ] },
        component: () => import('@/views/module/index.vue')
      },
      // 模块算法上传
      { 
        path: '/moduleCreate',
        name: 'moduleCreate',
        meta: { show: true, icon: 'icon-chuangjian', isLink: true, title: '算法模块上传', rewriteTitle: true, exclude: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER ] },
        component: () => import('@/views/module/moduleCreate.vue')
      }
    ]
  },
  // 策略配置
  {
    path: '/strategy',
    component: () => import('@/components/layout'),
    redirect: '/strategyManage',
    name: 'strategy',
    meta: { show: false, isLink: false, role: [ global.roles.ADMIN ] },
    children: [
      {
        path: '/strategyManage',
        name: 'strategyManage',
        component: () => import('@/views/strategy/strategyManage.vue'),
        meta: { show: true, index: true, icon: 'icon-yonghu1', isLink: true, title: '策略管理', rewriteTitle: true, role: [ global.roles.ADMIN ] }
      },
      {
        path: '/strategyCreate',
        name: 'strategyCreate',
        component: () => import('@/views/strategy/strategyCreate.vue'),
        // component: () => import('@/views/strategy/strategyCreateFix.vue'),
        meta: { show: false, index: false, isLink: true, title: '新增策略', exclude: true, role: [ global.roles.ADMIN ]}
      }
    ]
  },
  // 组合算法部分
  {
    path: '',
    component: () => import('@/components/layout'),
    redirect: '/algorithm',
    name: 'algorithm',
    meta: { show: true, icon: 'icon-a-suanfaguanli52', isLink: false, title: '算法组合生成', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER, global.roles.USER ] },
    children: [
      // 组合算法管理
      {
        path: '/algorithm',
        name: 'algorithmManage',
        meta: { show: true, icon: 'icon-shujumokuai', isLink: true, title: '算法管理', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER, global.roles.USER ]},
        component: () => import('@/views/algorithm/index.vue')
      },
      // 组合算法上传
      {
        path: '/algorithmCreate',
        name: 'algorithmCreate',
        meta: { show: true, icon: 'icon-newdocumentworksheet', isLink: true, title: '算法生成', rewriteTitle: true, exclude: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER, global.roles.USER ]},
        component: () => import('@/views/algorithm/image/algorithmCreate.vue')
      }
    ]
  },
  // 参数管理
  {
    path: '',
    component: () => import('@/components/layout'),
    redirect: '/parameter',
    name: 'parameter',
    meta: { show: true, icon: 'icon-canshupeizhi', isLink: false, title: '隐写算法参数', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER, global.roles.USER] },
    children: [
      // 参数管理
      {
        path: '/parameter',
        name: 'parameterManage',
        meta: { show: true, icon: 'icon-canshushezhi', isLink: true, title: '参数管理', rewriteTitle: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER, global.roles.USER]},
        component: () => import('@/views/parameter/index.vue')
      },
      // 参数创建
      {
        path: '/parameterCreate',
        name: 'parameterCreate',
        meta: { show: true, icon: 'icon-suanfa2', isLink: true, title: '参数生成', rewriteTitle: true, exclude: true, role: [ global.roles.ADMIN, global.roles.DEVELOPER, global.roles.USER ] },
        component: () => import('@/views/parameter/parameterCreate.vue')
      }
    ]
  },
  // 用户管理部分
  {
    path: '/user',
    component: () => import('@/components/layout'),
    redirect: '/userManage',
    name: 'user',
    meta: { show: false, isLink: false, role: [ global.roles.ADMIN ] },
    children: [
      {
        path: '/userManage',
        name: 'userManage',
        component: () => import('@/views/user/index.vue'),
        meta: { show: true, index: true, icon: 'icon-yonghu1', isLink: true, title: '用户管理', role: [ global.roles.ADMIN ] }
      },
      {
        path: '/userCreate',
        name: 'userCreate',
        component: () => import('@/views/user/userCreate.vue'),
        meta: { show: false, index: false, isLink: true, title: '新增用户',  exclude: true, role: [ global.roles.ADMIN ] }
      }
    ]
  }
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [...constantRoutes]
})

export default router
